<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            let old = {};
            let Div = new Proxy(old, {
                get: function (target, key) {
                    return function (type, data, ...child) {
                        if (typeof type === "number") {
                            //判断是否是数字
                            return type * 2; //如果是值X2返回
                        } else {
                            //创建一个标签
                            let Wwz = document.createElement(type);
                            // 返回值 ['id','class']
                            Object.keys(data).forEach((item) => {
                                //两个参数 1.属性名 2.属性值
                                Wwz.setAttribute(item, data[item]);
                            });
                            //返回Wwz  对应标签
                            return Wwz;
                        }
                    };
                },
            });

            let res = Div.createElement(
                "h2",
                { id: "Hazi", class: "main" },
                "这是一个懂东东"
            );
            console.log(res);
        </script>
    </body>
</html>
